package com.kly.sc.api.integration.userplatform.util;

import org.json.JSONObject;

/**
 * @author linqu
 */
public abstract class Entity {
    private JSONObject modelJson;
    private final String CREATED_AT = "created_at";
    private final String CAPTURED_AT = "captured_at";

    public Entity(JSONObject jsonObject) {
        this.modelJson = jsonObject;
    }

    public <T> T get(String key) {
        if (!this.has(key)) {
            return null;
        } else if (!key.equals(CREATED_AT) && !key.equals(CAPTURED_AT)) {
            Object value = this.modelJson.get(key);
            return value == null ? null : (T) value;
        } else {
            return null;
        }
    }

    public JSONObject toJson() {
        return this.modelJson;
    }

    public boolean has(String key) {
        return this.modelJson.has(key);
    }

    @Override
    public String toString() {
        return this.modelJson.toString();
    }
}
